package com.course.web.model;

import com.course.util.DateUtils;
import com.course.util.TimeUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.Date;

/**
 * Created by Justin on 2017/6/14.
 */
@Data
@EqualsAndHashCode(of = {"id"})
public class ClassItemVM implements HasID {
    @Min(0)
    private int id;
    @Min(0)
    private int studentId;
    @Min(0)
    private int teacherId;
    @Min(0)
    private int courseId;
    @Min(0)
    private int taskId;
    @Min(0)
    private int planId;
    @NotNull
    private Date dateTime;
    private String room;
    private String task;
    private String student;
    private String teacher;
    private String link;

    private int time;
    private LocalDate date;

    public void setTime(int time) {
        this.time = time;
        syncDate();
    }

    public void syncDate() {
        int hou = TimeUtils.getHH(time);
        int min = TimeUtils.getMM(time);
        dateTime = DateUtils.toDate(date.getYear(), date.getMonthValue(), date.getDayOfMonth(), hou, min);
    }

    public void syncTime() {
        date = DateUtils.toLocalDate(dateTime);
        LocalTime localTime = DateUtils.toLocalTime(dateTime);
        time = TimeUtils.toTime(localTime.getHour(), localTime.getMinute());
    }
}
